<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="org.json.*"%>
<%@ page import="com.gzgi.framework.*"%>
<%@ page import="com.gzgi.framework.util.*"%>
<%@ page import="com.gzgi.framework.context.*"%>
<%@ page import="com.gzgi.framework.config.*"%>
<%@ page import="com.gzgi.framework.integration.*"%>
<%@ page import="com.gzgi.framework.sys.model.*"%>
<%@ page import="com.gzgi.framework.tree.*"%>
<%@ page import="com.gzgi.framework.tree.helper.*"%>
<%
     String node = request.getParameter("node");
	 TreeModelHelper helper = new TreeModelHelper();
     Map paramMap = new HashMap();
     if(node != null){
		 if("0".equals(node)){
			  TreeModel treeModel = IntegrationFactory.getRootDepartment();
			  if(treeModel != null){
			      paramMap.put("parentId", treeModel.getId());
			  } else {
				  paramMap.put("code", "SYS_ORG");
			  }
		 } else {
		      paramMap.put("parentId", node);
			  paramMap.put("nodeId", node);
			  paramMap.put("node", node);
		 }
		 List treeModels = IntegrationFactory.getDepartmentList(paramMap);
		 JSONArray array = new JSONArray();
		 if(treeModels != null && treeModels.size() > 0){
			 for (int i = 0; i < treeModels.size(); i++) {
				TreeModel treeModel = (TreeModel) treeModels.get(i);
				JSONObject row = new JSONObject();
				row.put("id", treeModel.getId());
				row.put("text", treeModel.getName());
				row.put("leaf", new Boolean(false));
				row.put("checked",  new Boolean(false));
				array.put(row);
			 }
		 } else {
             Map  userMap = IntegrationFactory.getUserProfileMap(paramMap);
			 if(userMap !=null && userMap.size() > 0){
				  Iterator iter = userMap.values().iterator();
				  while(iter.hasNext()){
					    UserProfile u = (UserProfile)iter.next();
                        JSONObject row = new JSONObject();
						row.put("id", u.getActorId());
						row.put("text", u.getActorId() + "["+u.getName()+"]");
						row.put("leaf", new Boolean(true));
						row.put("checked",  new Boolean(false));
						array.put(row);
				  }
			 }
		 }
	     out.println(array);
	 }
%>